<?php

namespace maotool\core\console\command;

use maotool\core\console\Command;
use maotool\file\DirUtil;
use maotool\util\ImageUtil;

class Image extends Command
{

    public function getName()
    {
        // TODO: Implement getName() method.
    }

    public function getDescription()
    {
        // TODO: Implement getDescription() method.
    }

    public function getHelp($argv = [])
    {
        return "image 图像工具";
    }

    public function getUsage($argv = [])
    {
        // TODO: Implement getUsage() method.
    }

    public function isHit($argv = [])
    {
        if (count($argv) > 1 && $argv[1] == "image") {
            return true;
        }
        return false;
    }

    public function handle($argv = [])
    {
        $path = $argv[count($argv) - 1];
        $files = DirUtil::scanFiles($path);
        foreach ($files as $file) {
            if (ImageUtil::isImage($file['path'])) {
                if (ImageUtil::isSquare($file['path'])) {
                    ImageUtil::resize($file['path'], "500max");
                } else if (ImageUtil::isVertical($file['path'])) {
                    ImageUtil::resize($file['path'], null, "1000max");
                } else if (ImageUtil::isHorizontal($file['path'])) {
                    if (ImageUtil::isNarrow($file['path'])) {
                        ImageUtil::resize($file['path'], "300max");
                    } else {
                        ImageUtil::resize($file['path'], "1000max");
                    }
                }
                ImageUtil::compress($file['path'], 70);
                echo $file['path'] . "\n";
            }
        }
        return "image";
    }

}